<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tip-box{
            width: 200px;
            height: 200px;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            background-color: rgba(0, 0, 0, 0.8);
            color: white;
            font-size: 20px;
            text-align: center;
            padding: 20px;
        }
        .tip-box>img{
            width: 100%;
            height: 70%;
            object-fit: contain;
            object-position: center;
        }
        .tip-box>div{
            height: 60px;
            line-height: 60px;
            
        }
    </style>
    <script src="../assets/js/vue.js"></script>
</head>
<body>
    <input type="button" value="loading" onclick="loadFun()">
    <input type="button" value="success" onclick="successFun()">
    <input type="button" value="error" onclick="errorFun()">
   
</body>
<script>
    let tip=null;
    Tip=Vue.extend({
        template:` <div class="tip-box">
        <img :src="type[at].icon" alt="">
        <div>{{ type[at].defaultMsg}}</div>
        </div>`,
        data(){
            return{
                type:{
                    loading:{
                        icon:"../assets/img/loading.gif",
                        defaultMsg:"loading",
                    },
                    success:{
                        icon:"../assets/img/success.png",
                        defaultMsg:"success",
                    },
                    error:{
                        icon:"../assets/img/error.png",
                        defaultMsg:"error",
                    },
                    msg:null,
                    at:"loading",
                }
            }
        },
        created() {
            this.$mount();
        },
        mounted() {
            document.body.appendChild(this.$el);
            setTimeout(() =>{this.$destroy()
             } ,3000)
        },
        destroyed() {
            document.body.removeChild(this.$el);
        },
    })
    function loadFun(msg){
        if(tip){
            
        }else{
            new Tip({
                data:{
                    msg:msg,
                    at:"loading"
                }
            })   
        }

    }
    function successFun(msg){
        new Tip({
            data:{
                msg:msg,
                at:"success"
            }
        })
    }
    function errorFun(msg){
        new Tip({
            data:{
                msg:msg,
                at:"error"
            }
        })
    }
</script>
</html>